Do the following using R. You must also turn in a copy of your R code. (1) Plot the Binomial(n = 47, θ = 0.8) pmf. Make sure the plot is properly labeled.
n <- 47
theta <- 0.8
X <- 1:n
fX <- dbinom(X,n,theta)
plot(X, fX, type = 'h', lwd = 3, main = 'X~Binom(47,0.8)', xlab = 'X', ylab = 'f(x) (Density)')
n*theta
## [1] 37.6
sqrt(n*theta*(1-theta))
## [1] 2.742262
dbinom(3,11,.5)
## [1] 0.08056641
dbinom(3,11,.31)
## [1] 0.2525584
dbinom(3,11,.27)
## [1] 0.2619136
Insert Proof
X <- seq(0,1,length.out=1001)
plot(X,dbeta(X,shape1 = 5, shape2 = 11),
col = 'black', lwd = 2, type = 'l',
main = 'Beta(3,5) & Beta(5,11)',
xlab = 'X',
ylab = 'f(x)')
lines(X,dbeta(X, shape1 = 3, shape2 = 5),
col = 'gray', lwd = 2)
legend(.75, 3, legend=c("Beta(5,11)", "Beta(3,5)"),
col=c("black", "gray"), lty = 1, lwd = 2, cex = 1)
dbeta(.24, shape1 = 1, shape2 = 8)
## [1] 1.171616
pbeta(.13, shape1 = 1, shape2 = 8)
## [1] 0.6717883
1 - pbeta(.4, shape1 = 3, shape2 = 9)
## [1] 0.1189168
pbeta(.7,shape1 = 18, shape2 = 4.4) - pbeta(.6,shape1 = 18, shape2 = 4.4)
## [1] 0.09770375
qbeta(.71, shape1 = 4, shape2 = 7)
## [1] 0.438946
qbeta(.2, shape1 = 12.2, shape2 = 25.7)
## [1] 0.2572049
a <- 3.1
b <- 4.8
a / (a+b)
## [1] 0.3924051
a <- 3
b <- 5
(a*b) / (((a+b)**2) * ((a+b+1)))
## [1] 0.02604167
a <- 2.8
b <- 2.1
(a−1) / (a+b−2)
## [1] 0.6206897
Insert Proof
Refer again to question 4. In general terms, what is the posterior distribution for θ given the results of the clinical trial described in question 4 and assuming a beta(a,b) prior distribution for θ.
Refer again to question 4. For this problem and assuming a beta(a,b) prior, what is \[\int_0^1 f(y|θ)π(θ)~dθ \]
Refer again to question 4. Create one figure with two plots (i.e., use par(mfrow=c(1,2))). Each plot will contain two curves, a red one representing the prior distribution of θ and a blue representing the posterior distribution of θ. For the left plot, use a beta(1,1) prior distribution. Comment on what this prior distribution implies regarding prior beliefs of the analyst and the impact it has on the posterior. For the right plot, use a beta(25,1) prior distribution. Comment on what this prior distribution implies regarding prior beliefs of the analyst and the impact it has on the posterior.